Conditions | 1 |
Paths | 1 |
Total Lines | 127 |
Lines | 127 |
Ratio | 100 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | View Code Duplication | var assert = require('chai').assert, |
|
4 | describe('Conclusion', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | var newConclusion = new GedcomX.Conclusion(), |
||
8 | conclusion = GedcomX.Conclusion(); |
||
9 | assert.instanceOf(newConclusion, GedcomX.Conclusion, 'An instance of Conclusion is not returned when calling the constructor with new.'); |
||
10 | assert.instanceOf(conclusion, GedcomX.Conclusion, 'An instance of Conclusion is not returned when calling the constructor without new.'); |
||
11 | }); |
||
12 | |||
13 | it('Create with JSON', function(){ |
||
14 | var conclusion = GedcomX.Conclusion({ |
||
15 | id: 'conclusion', |
||
16 | lang: 'en', |
||
17 | analysis: { |
||
18 | resource: 'http://analysis/uri' |
||
19 | }, |
||
20 | confidence: 'http://gedcomx.org/High', |
||
21 | attribution: { |
||
22 | created: 1145667891 |
||
23 | }, |
||
24 | sources: [ |
||
25 | { |
||
26 | description: 'http://description/uri' |
||
27 | } |
||
28 | ], |
||
29 | notes: [ |
||
30 | { |
||
31 | subject: 'Note title', |
||
32 | text: 'Note text' |
||
33 | } |
||
34 | ] |
||
35 | }); |
||
36 | assert.equal(conclusion.getId(), 'conclusion'); |
||
37 | assert.equal(conclusion.getLang(), 'en'); |
||
38 | assert.equal(conclusion.getAnalysis().getResource(), 'http://analysis/uri'); |
||
39 | assert.equal(conclusion.getConfidence(), 'http://gedcomx.org/High'); |
||
40 | assert.equal(conclusion.getAttribution().getCreated().getTime(), 1145667891); |
||
41 | assert.equal(conclusion.getSources().length, 1); |
||
42 | assert.equal(conclusion.getSources()[0].getDescription(), 'http://description/uri'); |
||
43 | assert.equal(conclusion.getNotes().length, 1); |
||
44 | assert.equal(conclusion.getNotes()[0].getSubject(), 'Note title'); |
||
45 | assert.equal(conclusion.getNotes()[0].getText(), 'Note text'); |
||
46 | }); |
||
47 | |||
48 | it('Create with mixed data', function(){ |
||
49 | var conclusion = GedcomX.Conclusion({ |
||
50 | id: 'conclusion', |
||
51 | lang: 'en', |
||
52 | confidence: 'http://gedcomx.org/High', |
||
53 | sources: [ |
||
54 | GedcomX.SourceReference({ description: 'http://description/uri' }) |
||
55 | ], |
||
56 | notes: [ |
||
57 | GedcomX.Note({ |
||
58 | subject: 'Note title', |
||
59 | text: 'Note text' |
||
60 | }) |
||
61 | ] |
||
62 | }); |
||
63 | assert.equal(conclusion.getId(), 'conclusion'); |
||
64 | assert.equal(conclusion.getLang(), 'en'); |
||
65 | assert.equal(conclusion.getConfidence(), 'http://gedcomx.org/High'); |
||
66 | assert.equal(conclusion.getSources().length, 1); |
||
67 | assert.equal(conclusion.getSources()[0].getDescription(), 'http://description/uri'); |
||
68 | assert.equal(conclusion.getNotes().length, 1); |
||
69 | assert.equal(conclusion.getNotes()[0].getSubject(), 'Note title'); |
||
70 | assert.equal(conclusion.getNotes()[0].getText(), 'Note text'); |
||
71 | }); |
||
72 | |||
73 | it('Build', function(){ |
||
74 | var conclusion = GedcomX.Conclusion() |
||
75 | .setId('conclusion') |
||
76 | .setLang('en') |
||
77 | .setConfidence('http://gedcomx.org/High') |
||
78 | .addSource( |
||
79 | GedcomX.SourceReference() |
||
80 | .setDescription('http://description/uri') |
||
81 | ) |
||
82 | .addNote( |
||
83 | GedcomX.Note() |
||
84 | .setSubject('Note title') |
||
85 | .setText('Note text') |
||
86 | ); |
||
87 | assert.equal(conclusion.getId(), 'conclusion'); |
||
88 | assert.equal(conclusion.getLang(), 'en'); |
||
89 | assert.equal(conclusion.getConfidence(), 'http://gedcomx.org/High'); |
||
90 | assert.equal(conclusion.getSources().length, 1); |
||
91 | assert.equal(conclusion.getSources()[0].getDescription(), 'http://description/uri'); |
||
92 | assert.equal(conclusion.getNotes().length, 1); |
||
93 | assert.equal(conclusion.getNotes()[0].getSubject(), 'Note title'); |
||
94 | assert.equal(conclusion.getNotes()[0].getText(), 'Note text'); |
||
95 | }); |
||
96 | |||
97 | it('toJSON', function(){ |
||
98 | var conclusionData = { |
||
99 | id: 'conclusion', |
||
100 | lang: 'en', |
||
101 | analysis: { |
||
102 | resource: 'http://analysis/uri' |
||
103 | }, |
||
104 | confidence: 'http://gedcomx.org/High', |
||
105 | attribution: { |
||
106 | created: 1145667891 |
||
107 | }, |
||
108 | sources: [ |
||
109 | { |
||
110 | description: 'http://description/uri' |
||
111 | } |
||
112 | ], |
||
113 | notes: [ |
||
114 | { |
||
115 | subject: 'Note title', |
||
116 | text: 'Note text' |
||
117 | } |
||
118 | ] |
||
119 | }, |
||
120 | conclusion = GedcomX.Conclusion(conclusionData); |
||
121 | assert.deepEqual(conclusion.toJSON(), conclusionData); |
||
122 | }); |
||
123 | |||
124 | it('constructor does not copy instances', function(){ |
||
125 | var obj1 = GedcomX.Conclusion(); |
||
126 | var obj2 = GedcomX.Conclusion(obj1); |
||
127 | assert.strictEqual(obj1, obj2); |
||
128 | }); |
||
129 | |||
130 | }); |